package com.chenqing.baike.controller;

import com.chenqing.baike.service.SearchService;
import com.chenqing.baike.service.Spider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;


@Controller
public class SearchController {
    @Autowired
    private SearchService searchService;
    @GetMapping(value = "/search/{title}")
    public String search(Model model, @PathVariable String title){
        boolean hasResult=searchService.hasResult(title);
        if(!hasResult){
            Spider.socket(title);
        }
        model.addAttribute("hasResult",hasResult);
        return "search/search";
    }
}
